package com.bgs.controller;

import com.bgs.annotation.NoneAuth;
import com.bgs.common.R;
import com.bgs.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author Asia
 * @version 1.0
 * @description: TODO
 * @date 2021/8/12 15:05
 */
@RestController
@Api(tags = "登录",description = "控制器")
public class TokenController {
    @Autowired
    private TokenService service;

    @NoneAuth
    @PostMapping("user/login")
    @ApiOperation("登录方法，返回Token")
    public R login(@RequestBody Map<String,String> info) {
        return service.login(info);
    }

    @GetMapping("user/info")
    @ApiOperation("获取用户信息")
    public R userInfo(HttpServletRequest request) {
        return service.userInfo(request);
    }

    @PostMapping("user/logout")
    @ApiOperation("登出方法-清除Token")
    public R logout(HttpServletRequest request) {
        return service.logout(request);
    }

    @NoneAuth
    @RequestMapping("/err/acl")
    public R err_acl() {
        return R.error().message("权限未认证,请重新登录");
    }
}
